$(function () {
    //1.点击退出
    $('.esc').on('click', function () {
        localStorage.removeItem('token');
        location.href = './login.html';
    })

    //2. 操作头像和欢迎词
    let layer = layui.layer;
    getUserInfo()
    function getUserInfo() {
        axios({
            url: '/my/userinfo',
            // headers: {
            //     Authorization: localStorage.getItem('token'),
            // },
        }).then(res => {
            // console.log(res.data.data);
            if (res.data.status !== 0) {
                return layer.msg(res.data.message);
            }
            randerUserInfo(res.data.data)
        })
    }
    function randerUserInfo(user) {
        let name = user.nickname || user.username;
        // console.log(name);
        $('.welcome').html('欢迎 ' + name);
        if (user.user_pic === null) {
            let first = name[0].toUpperCase();
            $('.avatar-text').show().html(first);
            $('.userinfo img').hide();
        } else {
            $('.avatar-text').hide();
            $('.userinfo img').show().attr('src', user.user_pic)
        }
        
    }
})